Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polkadot-sdk-docs: Use command_macro! #6624

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

ndkazu
Copy link
Contributor

@ndkazu ndkazu commented Nov 23, 2024

Description

Understood assignment:
Initial assignment description is in #6194 : find every occurrence of #[docify::export] where process:Command is used → replace the use of process:Command by command_macro!

Issues observed:

  • The tests using #[docify::export] & process:Command are failing to begin with (tested & worked on: ~/polkadot-sdk/docs/sdk/src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs)
  • Probably due to a lack of maintenenance of the crate command_macro the following file needed some modifications: ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/command-macros-plugin-0.2.7/src/lib.rs

I am running cargo +nightly test from ~/polkadot-sdk/docs/sdk/src/reference_docs/chain_spec_runtime/

Same test failures are observed after changing from process:Command to command_macro!

Some assistance is needed.

@iulianbarbu
Copy link
Contributor

Can you please use cmd_lib instead of command_macro? We already use it with chain-spec-builder and works fine.

@ndkazu
Copy link
Contributor Author

ndkazu commented Nov 26, 2024

Can you please use cmd_lib instead of command_macro? We already use it with chain-spec-builder and works fine.

@iulianbarbu, I used a slightly modified version of the macro used in chain-spec-builder, and now cmd_lib seems to work fine. However, I am still facing a BIG problem: The tests were failing in the first place: output.stdout was an empty [u8] (You can see it in the test generate_chain_spec). For now I can confirm that the tests are failing the same way after modification, but this isn't enough.

docs/sdk/src/reference_docs/chain_spec_runtime/Cargo.toml Outdated Show resolved Hide resolved
@@ -88,9 +84,8 @@ fn generate_chain_spec() {
.arg("preset_2")
.output()
.expect("Failed to execute command");

println!("Expected: {:?}", output.stdout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder to remove once debugging is done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responding to this comment: #6624 (comment). Is there anything present at WASM_FILE_PATH on your machine? Also, would be great to check the exit code, because it surely failed if the output is empty.

Did you try running the same cmd in terminal to see how it fails or if it works?

Copy link
Contributor Author

@ndkazu ndkazu Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iulianbarbu , you were right: nothing in the WASM_FILE_PATH environment variable, and yes the output is empty.
Running "../../../../../target/release/chain-spec-builder" list-presets -r $WASM_FILE_PATH from the command line after running the cargo build and setting the environment variable manually, I get the following error:
wasm blob shall be readable No such file or directory (os error 2)

Copy link
Contributor Author

@ndkazu ndkazu Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iulianbarbu , the chain-spec-guide-runtime/ folder is missing from the target/release/wbuild/ folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do a cargo build --release -p chain-spec-guide-runtime and try again? Seems like tests depends on the runtime to be built prior to running it. Or even better, running a cargo build --release -p polkadot-sdk-docs should build everything that's needed most probably.

Copy link
Contributor Author

@ndkazu ndkazu Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iulianbarbu , it worked!!!
Now the real work can start!!! 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional question: shall I remove Command::new(...) wherever it is used, or only where #[docify::export] is used?

Copy link
Contributor

@iulianbarbu iulianbarbu Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that modifying wherever it is used should be fine (not a must, up to you), but mainly important to update in the portions with #[docify::export]. BTW, would be great to extract the cmd_lib based commands in separate functions where we have #[docify::export_content], leaving the assertion logic to a test which isn't exported in the docs. This example might help: https://github.com/paritytech/polkadot-sdk/blob/master/substrate/bin/utils/chain-spec-builder/tests/test.rs#L237.

@ndkazu
Copy link
Contributor Author

ndkazu commented Nov 28, 2024

Bot fmt and label needed 👀

@iulianbarbu iulianbarbu added T11-documentation This PR/Issue is related to documentation. R0-silent Changes should not be mentioned in any release notes labels Nov 28, 2024
Copy link
Contributor

@iulianbarbu iulianbarbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost there I think, thanks!

Comment on lines 57 to 67
bash!(
chain-spec-builder {
"presets":[
"preset_1",
"preset_2",
"preset_3",
"preset_4",
"preset_invalid"
]
}, list-presets -r $path
);
Copy link
Contributor

@iulianbarbu iulianbarbu Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two remarks that apply to all the tests:

  1. Can we not assert inside the bash! macro? Just want to avoid passing the expected value to it, and hence display it in the docs too.
  2. Can we use #[docify::export_content] instead of #[docify::export]? In this way we'll export only the function content, ignoring its signature.

The idea is to assert in the test which calls this function (e.g. list_presets()), and the function to return a String that can be parsed as JSON accordingly. In the end the command we'll appear in the docs like:

bash!(
    chain-spec-builder list-presets -r $RUNTIME_PATH
)

LMK if this doesn't make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T11-documentation This PR/Issue is related to documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants